home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pwxms.zip / XMS.TXT < prev   
Text File  |  1993-01-04  |  36KB  |  829 lines

  1. eXtended Memory Specification (XMS), ver 2.0
  2.  
  3.  
  4. July 19, 1988
  5.  
  6.  
  7. Copyright (c) 1988, Microsoft Corporation, Lotus Development
  8. Corporation, Intel Corporation, and AST Research, Inc.
  9.  
  10. Microsoft Corporation                                            
  11. Box 97017
  12. 16011 NE 36th Way                                       
  13. Redmond, WA 98073
  14.  
  15. LOTUS (r)
  16. INTEL (r)
  17. MICROSOFT (r)
  18. AST (r) Research
  19.  
  20. This specification was jointly developed by Microsoft Corporation,
  21. Lotus Development Corporation, Intel Corporation,and AST Research,
  22. Inc. Although it has been released into the public domain and is not
  23. confidential or proprietary, the specification is still the copyright
  24. and property of Microsoft Corporation, Lotus Development Corporation,
  25. Intel Corporation, and AST Research, Inc.
  26.  
  27. Disclaimer of Warranty
  28.  
  29. MICROSOFT CORPORATION, LOTUS DEVELOPMENT CORPORATION, INTEL
  30. CORPORATION, AND AST RESEARCH, INC., EXCLUDE ANY AND ALL IMPLIED
  31. WARRANTIES, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  32. PARTICULAR PURPOSE. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST
  33. RESEARCH MAKE ANY WARRANTY OF REPRESENTATION, EITHER EXPRESS OR
  34. IMPLIED, WITH RESPECT TO THIS SPECIFICATION, ITS QUALITY,
  35. PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  36. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST RESEARCH SHALL HAVE ANY
  37. LIABILITY FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
  38. OUT OF OR RESULTING FROM THE USE OR MODIFICATION OF THIS
  39. SPECIFICATION.
  40.  
  41. This specification uses the following trademarks:
  42.  
  43. Intel is a registered trademark of Intel Corporation, Microsoft is a
  44. registered trademark of Microsoft Corporation, Lotus is a registered
  45. trademark of Lotus Development Corporation, and AST is a registered
  46. trademark of AST Research, Inc.
  47.  
  48.  
  49.                        Extended Memory Specification
  50.                        =============================
  51.  
  52.     The purpose of this document is to define the Extended Memory Specifica-
  53. tion (XMS) version 2.00 for MS-DOS.  XMS allows DOS programs to utilize
  54. additional memory found in Intel's 80286 and 80386 based machines in
  55. a consistent, machine independent manner.  With some restrictions, XMS adds
  56. almost 64K to the 640K which DOS programs can access directly.    Depending on
  57. available hardware, XMS may provide even more memory to DOS programs.  XMS
  58. also provides DOS programs with a standard method of storing data in extended
  59. memory.
  60.  
  61. DEFINITIONS:
  62. ------------
  63.  
  64.     Extended
  65.     Memory      -   Memory in 80286 and 80386 based machines which is located
  66.                     above the 1MB address boundary.
  67.  
  68.     High Memory
  69.     Area (HMA)  -   The first 64K of extended memory.  The High Memory
  70.             Area is unique because code can be executed in it while
  71.             in real mode.  The HMA officially starts at FFFF:10h
  72.             and ends at FFFF:FFFFh making it 64K-16 bytes in length.
  73.                     
  74.     Upper Memory
  75.     Blocks (UMBs)-  Blocks of memory available on some 80x86 based machines
  76.                     which are located between DOS's 640K limit and the
  77.                     1MB address boundary.  The number, size, and location
  78.                     of these blocks vary widely depending upon the types
  79.                     of hardware adapter cards installed in the machine.
  80.                     
  81.     Extended Memory
  82.     Blocks (EMBs)-  Blocks of extended memory located above the HMA which
  83.                     can only be used for data storage.
  84.                     
  85.     A20 Line    -   The 21st address line of 80x86 CPUs.  Enabling the A20
  86.                     line allows access to the HMA.
  87.  
  88.     XMM         -   An Extended Memory Manager.  A DOS device driver which
  89.                     implements XMS.  XMMs are machine specific but allow
  90.             programs to use extended memory in a machine-independent
  91.             manner.
  92.     
  93.     HIMEM.SYS   -   The Extended Memory Manager currently being distributed
  94.                     by Microsoft.
  95.  
  96. Helpful Diagram:
  97.  
  98.     |                                                       |   Top of Memory
  99.     |                                                       |
  100.     |                                                       |
  101.     |                        /\                             |
  102.     |                       /||\                            |
  103.     |                        ||                             |
  104.     |                        ||                             |
  105.     |.......................................................|
  106.     |                                                       |
  107.     |                                                       |
  108.     |             Possible Extended Memory Block            |
  109.     |                                                       |
  110.     |                                                       |
  111.     |.......................................................|
  112.     |                        ||                             |
  113.     |                        ||                             |
  114.     |                       \||/                            |
  115.     |                        \/                             |
  116.     |                                                       |
  117.     |                                                       |
  118.     |       Other EMBs could exist above 1088K (1MB+64K)    |
  119.     |                                                       |
  120.     |                                                       |
  121.     |-------------------------------------------------------|   1088K
  122.     |                                                       |
  123.     |                                                       |
  124.     |                The High Memory Area                   |
  125.     |                                                       |
  126.     |                                                       |
  127.     |=======================================================|   1024K or 1MB
  128.     |                                                       |
  129.     |                        /\                             |
  130.     |                       /||\                            |
  131.     |                        ||                             |
  132.     |                        ||                             |
  133.     |.......................................................|
  134.     |                                                       |
  135.     |             Possible Upper Memory Block               |
  136.     |.......................................................|
  137.     |                        ||                             |
  138.     |                        ||                             |
  139.     |                       \||/                            |
  140.     |                        \/                             |
  141.     |                                                       |
  142.     |        Other UMBs could exist between 640K and 1MB    |
  143.     |                                                       |
  144.     |-------------------------------------------------------|   640K
  145.     |                                                       |
  146.     |                                                       |
  147.     |                                                       |
  148.     |             Conventional or DOS Memory                |
  149.     |                                                       |
  150.     |                                                       |
  151.     |                                                       |
  152.     |                                                       |
  153.     |                                                       |
  154.     +-------------------------------------------------------+   0K
  155. DRIVER INSTALLATION:
  156. --------------------
  157.  
  158.     An XMS driver is installed by including a DEVICE= statement in the
  159. machine's CONFIG.SYS file.  It must be installed prior to any other
  160. devices or TSRs which use it.  An optional parameter after the driver's 
  161. name (suggested name "/HMAMIN=") indicates the minimum amount of space in
  162. the HMA a program can use.  Programs which use less than the minimum will
  163. not be placed in the HMA.  See "Prioritizing HMA Usage" below for more
  164. information.  A second optional parameter (suggested name "/NUMHANDLES=")
  165. allows users to specify the maximum number of extended memory blocks which
  166. may be allocated at any time.
  167.  
  168.     NOTE: XMS requires DOS 3.00 or above.
  169.  
  170.  
  171. THE PROGRAMMING API:
  172. --------------------
  173.  
  174.     The XMS API Functions are accessed via the XMS driver's Control Function.
  175. The address of the Control Function is determined via INT 2Fh.  First, a
  176. program should determine if an XMS driver is installed.  Next, it should
  177. retrieve the address of the driver's Control Function.  It can then use any
  178. of the available XMS functions.  The functions are divided into several
  179. groups:
  180.  
  181.         1. Driver Information Functions (0h)
  182.         2. HMA Management Functions (1h-2h)
  183.     3. A20 Management Functions (3h-7h)
  184.         4. Extended Memory Management Functions (8h-Fh)
  185.         5. Upper Memory Management Functions (10h-11h)
  186.  
  187.  
  188. DETERMINING IF AN XMS DRIVER IS INSTALLED:
  189. ------------------------------------------
  190.  
  191.     The recommended way of determining if an XMS driver is installed is to
  192. set AH=43h and AL=00h and then execute INT 2Fh.  If an XMS driver is available,
  193. 80h will be returned in AL.
  194.  
  195.     Example:
  196.             ; Is an XMS driver installed?
  197.             mov     ax,4300h
  198.             int     2Fh         
  199.             cmp     al,80h  
  200.             jne     NoXMSDriver
  201.             
  202.  
  203. CALLING THE API FUNCTIONS:
  204. --------------------------
  205.  
  206.     Programs can execute INT 2Fh with AH=43h and AL=10h to obtain the address
  207. of the driver's control function.  The address is returned in ES:BX.  This
  208. function is called to access all of the XMS functions.  It should be called
  209. with AH set to the number of the API function requested.  The API function
  210. will put a success code of 0001h or 0000h in AX.  If the function succeeded
  211. (AX=0001h), additional information may be passed back in BX and DX.  If the
  212. function failed (AX=0000h), an error code may be returned in BL.  Valid
  213. error codes have their high bit set.  Developers should keep in mind that
  214. some of the XMS API functions may not be implemented by all drivers and will
  215. return failure in all cases.
  216.  
  217.     Example:
  218.             ; Get the address of the driver's control function
  219.             mov     ax,4310h
  220.             int     2Fh
  221.             mov     word ptr [XMSControl],bx        ; XMSControl is a DWORD
  222.             mov     word ptr [XMSControl+2],es
  223.             
  224.             ; Get the XMS driver's version number
  225.             mov     ah,00h
  226.             call    [XMSControl]    ; Get XMS Version Number
  227.  
  228.     NOTE: Programs should make sure that at least 256 bytes of stack space
  229.       is available before calling XMS API functions.
  230.  
  231.  
  232. API FUNCTION DESCRIPTIONS:
  233. --------------------------
  234.  
  235.     The following XMS API functions are available:
  236.  
  237.        0h)  Get XMS Version Number
  238.        1h)  Request High Memory Area
  239.        2h)  Release High Memory Area
  240.        3h)  Global Enable A20
  241.        4h)  Global Disable A20
  242.        5h)  Local Enable A20
  243.        6h)  Local Disable A20
  244.        7h)  Query A20
  245.        8h)  Query Free Extended Memory
  246.        9h)  Allocate Extended Memory Block
  247.        Ah)  Free Extended Memory Block
  248.        Bh)  Move Extended Memory Block
  249.        Ch)  Lock Extended Memory Block
  250.        Dh)  Unlock Extended Memory Block
  251.        Eh)  Get Handle Information
  252.        Fh)  Reallocate Extended Memory Block
  253.       10h)  Request Upper Memory Block
  254.       11h)  Release Upper Memory Block
  255.  
  256. Each is described below.
  257.  
  258.  
  259. Get XMS Version Number (Function 00h):
  260. --------------------------------------
  261.  
  262.     ARGS:   AH = 00h
  263.     RETS:   AX = XMS version number
  264.         BX = Driver internal revision number
  265.         DX = 0001h if the HMA exists, 0000h otherwise
  266.     ERRS:   None
  267.  
  268.     This function returns with AX equal to a 16-bit BCD number representing
  269. the revision of the DOS Extended Memory Specification which the driver
  270. implements (e.g. AX=0235h would mean that the driver implemented XMS version
  271. 2.35).    BX is set equal to the driver's internal revision number mainly for
  272. debugging purposes.  DX indicates the existence of the HMA (not its
  273. availability) and is intended mainly for installation programs.
  274.     
  275.     NOTE: This document defines version 2.00 of the specification.
  276.  
  277.  
  278. Request High Memory Area (Function 01h):
  279. ----------------------------------------
  280.  
  281.     ARGS:   AH = 01h
  282.             If the caller is a TSR or device driver,
  283.                 DX = Space needed in the HMA by the caller in bytes
  284.             If the caller is an application program,
  285.                 DX = FFFFh     
  286.     RETS:   AX = 0001h if the HMA is assigned to the caller, 0000h otherwise
  287.     ERRS:   BL = 80h if the function is not implemented
  288.         BL = 81h if a VDISK device is detected
  289.         BL = 90h if the HMA does not exist
  290.         BL = 91h if the HMA is already in use
  291.         BL = 92h if DX is less than the /HMAMIN= parameter
  292.  
  293.     This function attempts to reserve the 64K-16 byte high memory area for
  294. the caller.  If the HMA is currently unused, the caller's size parameter is
  295. compared to the /HMAMIN= parameter on the driver's command line.  If the
  296. value passed by the caller is greater than or equal to the amount specified
  297. by the driver's parameter, the request succeeds.  This provides the ability
  298. to ensure that programs which use the HMA efficiently have priority over
  299. those which do not.
  300.  
  301.     NOTE: See the sections "Prioritizing HMA Usage" and "High Memory Area
  302.           Restrictions" below for more information.
  303.  
  304.  
  305. Release High Memory Area (Function 02h):
  306. ----------------------------------------
  307.  
  308.     ARGS:   AH = 02h
  309.     RETS:   AX = 0001h if the HMA is successfully released, 0000h otherwise
  310.     ERRS:   BL = 80h if the function is not implemented
  311.         BL = 81h if a VDISK device is detected
  312.         BL = 90h if the HMA does not exist
  313.         BL = 93h if the HMA was not allocated
  314.  
  315.     This function releases the high memory area and allows other programs to
  316. use it.  Programs which allocate the HMA must release it before exiting.  
  317. When the HMA has been released, any code or data stored in it becomes invalid
  318. and should not be accessed.
  319.  
  320.  
  321. Global Enable A20 (Function 03h):
  322. ---------------------------------
  323.  
  324.     ARGS:   AH = 03h
  325.     RETS:   AX = 0001h if the A20 line is enabled, 0000h otherwise
  326.     ERRS:   BL = 80h if the function is not implemented
  327.         BL = 81h if a VDISK device is detected
  328.         BL = 82h if an A20 error occurs
  329.  
  330.     This function attempts to enable the A20 line.  It should only be used
  331. by programs which have control of the HMA.  The A20 line should be turned
  332. off via Function 04h (Global Disable A20) before a program releases control
  333. of the system.
  334.  
  335.     NOTE: On many machines, toggling the A20 line is a relatively slow
  336.           operation.
  337.  
  338.  
  339. Global Disable A20 (Function 04h):
  340. ----------------------------------
  341.  
  342.     ARGS:   AH = 04h
  343.     RETS:   AX = 0001h if the A20 line is disabled, 0000h otherwise
  344.     ERRS:   BL = 80h if the function is not implemented
  345.         BL = 81h if a VDISK device is detected
  346.         BL = 82h if an A20 error occurs
  347.         BL = 94h if the A20 line is still enabled
  348.     
  349.     This function attempts to disable the A20 line.  It should only be used
  350. by programs which have control of the HMA.  The A20 line should be disabled
  351. before a program releases control of the system.
  352.  
  353.     NOTE: On many machines, toggling the A20 line is a relatively slow
  354.           operation.
  355.  
  356.  
  357. Local Enable A20 (Function 05h):
  358. --------------------------------
  359.  
  360.     ARGS:   AH = 05h
  361.     RETS:   AX = 0001h if the A20 line is enabled, 0000h otherwise
  362.     ERRS:   BL = 80h if the function is not implemented
  363.         BL = 81h if a VDISK device is detected
  364.         BL = 82h if an A20 error occurs
  365.  
  366.     This function attempts to enable the A20 line.  It should only be used
  367. by programs which need direct access to extended memory.  Programs which use
  368. this function should call Function 06h (Local Disable A20) before releasing
  369. control of the system.
  370.  
  371.     NOTE: On many machines, toggling the A20 line is a relatively slow
  372.           operation.
  373.  
  374.  
  375. Local Disable A20 (Function 06h):
  376. ---------------------------------
  377.  
  378.     ARGS:   AH = 06h
  379.     RETS:   AX = 0001h if the function succeeds, 0000h otherwise
  380.     ERRS:   BL = 80h if the function is not implemented
  381.         BL = 81h if a VDISK device is detected
  382.         BL = 82h if an A20 error occurs
  383.         BL = 94h if the A20 line is still enabled
  384.  
  385.     This function cancels a previous call to Function 05h (Local Enable
  386. A20).  It should only be used by programs which need direct access to
  387. extended memory.  Previous calls to Function 05h must be canceled before
  388. releasing control of the system.
  389.  
  390.     NOTE: On many machines, toggling the A20 line is a relatively slow
  391.           operation.
  392.  
  393.  
  394. Query A20 (Function 07h):
  395. -------------------------
  396.  
  397.     ARGS:   AH = 07h
  398.     RETS:   AX = 0001h if the A20 line is physically enabled, 0000h otherwise
  399.     ERRS:   BL = 00h if the function succeeds
  400.         BL = 80h if the function is not implemented
  401.         BL = 81h if a VDISK device is detected
  402.  
  403.     This function checks to see if the A20 line is physically enabled.  It
  404. does this in a hardware independent manner by seeing if "memory wrap" occurs.
  405.  
  406.  
  407. Query Free Extended Memory (Function 08h):
  408. ------------------------------------------
  409.  
  410.     ARGS:   AH = 08h
  411.     RETS:   AX = Size of the largest free extended memory block in K-bytes
  412.         DX = Total amount of free extended memory in K-bytes
  413.     ERRS:   BL = 80h if the function is not implemented
  414.         BL = 81h if a VDISK device is detected
  415.         BL = A0h if all extended memory is allocated
  416.  
  417.     This function returns the size of the largest available extended memory
  418. block in the system.
  419.  
  420.     NOTE: The 64K HMA is not included in the returned value even if it is
  421.       not in use.
  422.  
  423.  
  424. Allocate Extended Memory Block (Function 09h):
  425. ----------------------------------------------
  426.  
  427.     ARGS:   AH = 09h
  428.             DX = Amount of extended memory being requested in K-bytes
  429.     RETS:   AX = 0001h if the block is allocated, 0000h otherwise
  430.             DX = 16-bit handle to the allocated block
  431.     ERRS:   BL = 80h if the function is not implemented
  432.         BL = 81h if a VDISK device is detected
  433.         BL = A0h if all available extended memory is allocated
  434.         BL = A1h if all available extended memory handles are in use
  435.             
  436.     This function attempts to allocate a block of the given size out of the
  437. pool of free extended memory.  If a block is available, it is reserved
  438. for the caller and a 16-bit handle to that block is returned.  The handle
  439. should be used in all subsequent extended memory calls.  If no memory was
  440. allocated, the returned handle is null.
  441.  
  442.     NOTE: Extended memory handles are scarce resources.  Programs should
  443.       try to allocate as few as possible at any one time.  When all
  444.       of a driver's handles are in use, any free extended memory is
  445.       unavailable.
  446.  
  447.  
  448. Free Extended Memory Block (Function 0Ah):
  449. ------------------------------------------
  450.  
  451.     ARGS:   AH = 0Ah
  452.             DX = Handle to the allocated block which should be freed
  453.     RETS:   AX = 0001h if the block is successfully freed, 0000h otherwise
  454.     ERRS:   BL = 80h if the function is not implemented
  455.         BL = 81h if a VDISK device is detected
  456.         BL = A2h if the handle is invalid
  457.         BL = ABh if the handle is locked
  458.  
  459.     This function frees a block of extended memory which was previously
  460. allocated using Function 09h (Allocate Extended Memory Block).  Programs
  461. which allocate extended memory should free their memory blocks before
  462. exiting.  When an extended memory buffer is freed, its handle and all data
  463. stored in it become invalid and should not be accessed.
  464.  
  465.  
  466. Move Extended Memory Block (Function 0Bh):
  467. ------------------------------------------
  468.  
  469.     ARGS:   AH = 0Bh
  470.             DS:SI = Pointer to an Extended Memory Move Structure (see below)
  471.     RETS:   AX = 0001h if the move is successful, 0000h otherwise
  472.     ERRS:   BL = 80h if the function is not implemented
  473.         BL = 81h if a VDISK device is detected
  474.         BL = 82h if an A20 error occurs
  475.         BL = A3h if the SourceHandle is invalid
  476.         BL = A4h if the SourceOffset is invalid
  477.         BL = A5h if the DestHandle is invalid
  478.         BL = A6h if the DestOffset is invalid
  479.         BL = A7h if the Length is invalid
  480.         BL = A8h if the move has an invalid overlap
  481.         BL = A9h if a parity error occurs
  482.  
  483.     Extended Memory Move Structure Definition:
  484.  
  485.         ExtMemMoveStruct    struc
  486.             Length              dd  ?   ; 32-bit number of bytes to transfer
  487.             SourceHandle        dw  ?   ; Handle of source block
  488.             SourceOffset        dd  ?   ; 32-bit offset into source 
  489.             DestHandle          dw  ?   ; Handle of destination block
  490.             DestOffset          dd  ?   ; 32-bit offset into destination block
  491.         ExtMemMoveStruct    ends
  492.             
  493.     This function attempts to transfer a block of data from one location to
  494. another.  It is primarily intended for moving blocks of data between
  495. conventional memory and extended memory, however it can be used for moving
  496. blocks within conventional memory and within extended memory.
  497.  
  498.     NOTE: If SourceHandle is set to 0000h, the SourceOffset is interpreted
  499.           as a standard segment:offset pair which refers to memory that is
  500.           directly accessible by the processor.  The segment:offset pair
  501.           is stored in Intel DWORD notation.  The same is true for DestHandle
  502.           and DestOffset.
  503.           
  504.       SourceHandle and DestHandle do not have to refer to locked memory
  505.       blocks.
  506.           
  507.       Length must be even.    Although not required, WORD-aligned moves
  508.       can be significantly faster on most machines.  DWORD aligned move
  509.       can be even faster on 80386 machines.
  510.           
  511.       If the source and destination blocks overlap, only forward moves
  512.       (i.e. where the source base is less than the destination base) are
  513.       guaranteed to work properly.
  514.           
  515.       Programs should not enable the A20 line before calling this
  516.       function.  The state of the A20 line is preserved.
  517.  
  518.       This function is guaranteed to provide a reasonable number of
  519.       interrupt windows during long transfers.
  520.           
  521.           
  522. Lock Extended Memory Block (Function 0Ch):
  523. ------------------------------------------
  524.  
  525.     ARGS:   AH = 0Ch
  526.             DX = Extended memory block handle to lock
  527.     RETS:   AX = 0001h if the block is locked, 0000h otherwise
  528.         DX:BX = 32-bit linear address of the locked block
  529.     ERRS:   BL = 80h if the function is not implemented
  530.         BL = 81h if a VDISK device is detected
  531.         BL = A2h if the handle is invalid
  532.         BL = ACh if the block's lock count overflows
  533.         BL = ADh if the lock fails
  534.             
  535.     This function locks an extended memory block and returns its base 
  536. address as a 32-bit linear address.  Locked memory blocks are guaranteed not
  537. to move.  The 32-bit pointer is only valid while the block is locked.
  538. Locked blocks should be unlocked as soon as possible.
  539.  
  540.     NOTE: A block does not have to be locked before using Function 0Bh (Move
  541.           Extended Memory Block).
  542.           
  543.       "Lock counts" are maintained for EMBs.
  544.  
  545.  
  546. Unlock Extended Memory Block (Function 0Dh):
  547. --------------------------------------------
  548.  
  549.     ARGS:   AH = 0Dh
  550.             DX = Extended memory block handle to unlock
  551.     RETS:   AX = 0001h if the block is unlocked, 0000h otherwise
  552.     ERRS:   BL = 80h if the function is not implemented
  553.         BL = 81h if a VDISK device is detected
  554.         BL = A2h if the handle is invalid
  555.         BL = AAh if the block is not locked
  556.     
  557.     This function unlocks a locked extended memory block.  Any 32-bit
  558. pointers into the block become invalid and should no longer be used.
  559.  
  560.  
  561. Get EMB Handle Information (Function 0Eh):
  562. ------------------------------------------
  563.  
  564.     ARGS:   AH = 0Eh
  565.         DX = Extended memory block handle
  566.     RETS:   AX = 0001h if the block's information is found, 0000h otherwise
  567.         BH = The block's lock count
  568.         BL = Number of free EMB handles in the system
  569.         DX = The block's length in K-bytes
  570.     ERRS:   BL = 80h if the function is not implemented
  571.         BL = 81h if a VDISK device is detected
  572.         BL = A2h if the handle is invalid
  573.  
  574.     This function returns additional information about an extended memory
  575. block to the caller.
  576.  
  577.     NOTE: To get the block's base address, use Function 0Ch (Lock Extended
  578.       Memory Block).
  579.           
  580.           
  581. Reallocate Extended Memory Block (Function 0Fh):
  582. ------------------------------------------------
  583.  
  584.     ARGS:   AH = 0Fh
  585.         BX = New size for the extended memory block in K-bytes
  586.         DX = Unlocked extended memory block handle to reallocate
  587.     RETS:   AX = 0001h if the block is reallocated, 0000h otherwise
  588.     ERRS:   BL = 80h if the function is not implemented
  589.         BL = 81h if a VDISK device is detected
  590.         BL = A0h if all available extended memory is allocated
  591.         BL = A1h if all available extended memory handles are in use
  592.         BL = A2h if the handle is invalid
  593.         BL = ABh if the block is locked
  594.  
  595.     This function attempts to reallocate an unlocked extended memory block
  596. so that it becomes the newly specified size.  If the new size is smaller
  597. than the old block's size, all data at the upper end of the old block is
  598. lost.
  599.  
  600.  
  601. Request Upper Memory Block (Function 10h):
  602. ------------------------------------------
  603.  
  604.     ARGS:   AH = 10h
  605.         DX = Size of requested memory block in paragraphs
  606.     RETS:   AX = 0001h if the request is granted, 0000h otherwise
  607.         BX = Segment number of the upper memory block
  608.             If the request is granted,
  609.         DX = Actual size of the allocated block in paragraphs
  610.         otherwise,
  611.         DX = Size of the largest available UMB in paragraphs
  612.     ERRS:   BL = 80h if the function is not implemented
  613.         BL = B0h if a smaller UMB is available
  614.         BL = B1h if no UMBs are available
  615.  
  616.     This function attempts to allocate an upper memory block to the caller.
  617. If the function fails, the size of the largest free UMB is returned in DX.
  618.  
  619.     NOTE: By definition UMBs are located below the 1MB address boundary.
  620.       The A20 Line does not need to be enabled before accessing an
  621.       allocated UMB.
  622.  
  623.       UMBs are paragraph aligned.
  624.  
  625.       To determine the size of the largest available UMB, attempt to
  626.       allocate one with a size of FFFFh.
  627.  
  628.       UMBs are unaffected by EMS calls.
  629.  
  630.  
  631. Release Upper Memory Block (Function 11h):
  632. ------------------------------------------
  633.  
  634.     ARGS:   AH = 11h
  635.         DX = Segment number of the upper memory block
  636.     RETS:   AX = 0001h if the block was released, 0000h otherwise
  637.     ERRS:   BL = 80h if the function is not implemented
  638.         BL = B2h if the UMB segment number is invalid
  639.  
  640.     This function frees a previously allocated upper memory block.  When an
  641. UMB has been released, any code or data stored in it becomes invalid and
  642. should not be accessed.
  643.  
  644.  
  645. PRIORITIZING HMA USAGE:
  646. -----------------------
  647.  
  648.     For DOS users to receive the maximum benefit from the High Memory Area,
  649. programs which use the HMA must store as much of their resident code in it as
  650. is possible.  It is very important that developers realize that the HMA is
  651. allocated as a single unit. 
  652.  
  653.     For example, a TSR program which grabs the HMA and puts 10K of code into
  654. it may prevent a later TSR from putting 62K into the HMA.  Obviously, regular
  655. DOS programs would have more memory available to them below the 640K line if
  656. the 62K TSR was moved into the HMA instead of the 10K one.
  657.  
  658.     The first method for dealing with conflicts such as this is to require 
  659. programs which use the HMA to provide a command line option for disabling
  660. this feature.  It is crucial that TSRs which do not make full use of the HMA
  661. provide such a switch on their own command line (suggested name "/NOHMA").
  662.  
  663.     The second method for optimizing HMA usage is through the /HMAMIN=
  664. parameter on the XMS device driver line.  The number after the parameter
  665. is defined to be the minimum amount of HMA space (in K-bytes) used by any
  666. driver or TSR.    For example, if "DEVICE=HIMEM.SYS /HMAMIN=48" is in a
  667. user's CONFIG.SYS file, only programs which request at least 48K would be
  668. allowed to allocate the HMA.  This number can be adjusted either by
  669. installation programs or by the user himself.  If this parameter is not
  670. specified, the default value of 0 is used causing the HMA to be allocated
  671. on a first come, first served basis.
  672.  
  673.     Note that this problem does not impact application programs.  If the HMA
  674. is available when an application program starts, the application is free to
  675. use as much or as little of the HMA as it wants.  For this reason,
  676. applications should pass FFFFh in DX when calling Function 01h.
  677.  
  678.  
  679. HIGH MEMORY AREA RESTRICTIONS:
  680. ------------------------------
  681.  
  682. -   Far pointers to data located in the HMA cannot be passed to DOS.  DOS
  683.     normalizes any pointer which is passed into it.  This will cause data
  684.     addresses in the HMA to be invalidated.
  685.  
  686. -   Disk I/O directly into the HMA (via DOS, INT 13h, or otherwise) is not
  687.     recommended.
  688.        
  689. -   Programs, especially drivers and TSRs, which use the HMA *MUST* use
  690.     as much of it as possible.  If a driver or TSR is unable to use at
  691.     least 90% of the available HMA (typically ~58K), they must provide
  692.     a command line switch for overriding HMA usage.  This will allow
  693.     the user to configure his machine for optimum use of the HMA.
  694.        
  695. -   Device drivers and TSRs cannot leave the A20 line permanently turned
  696.     on.  Several applications rely on 1MB memory wrap and will overwrite the
  697.     HMA if the A20 line is left enabled potentially causing a system crash.
  698.         
  699. -   Interrupt vectors must not point into the HMA.  This is a result of
  700.     the previous restriction.  Note that interrupt vectors can point into
  701.     any allocated upper memory blocks however.
  702.  
  703. ERROR CODE INDEX:
  704. -----------------
  705.  
  706. If AX=0000h when a function returns and the high bit of BL is set,
  707.  
  708.     BL=80h if the function is not implemented
  709.        81h if a VDISK device is detected
  710.        82h if an A20 error occurs
  711.        8Eh if a general driver error occurs
  712.        8Fh if an unrecoverable driver error occurs
  713.        90h if the HMA does not exist
  714.        91h if the HMA is already in use
  715.        92h if DX is less than the /HMAMIN= parameter
  716.        93h if the HMA is not allocated
  717.        94h if the A20 line is still enabled
  718.        A0h if all extended memory is allocated
  719.        A1h if all available extended memory handles are in use
  720.        A2h if the handle is invalid
  721.        A3h if the SourceHandle is invalid
  722.        A4h if the SourceOffset is invalid
  723.        A5h if the DestHandle is invalid
  724.        A6h if the DestOffset is invalid
  725.        A7h if the Length is invalid
  726.        A8h if the move has an invalid overlap
  727.        A9h if a parity error occurs
  728.        AAh if the block is not locked
  729.        ABh if the block is locked
  730.        ACh if the block's lock count overflows
  731.        ADh if the lock fails
  732.        B0h if a smaller UMB is available
  733.        B1h if no UMBs are available
  734.        B2h if the UMB segment number is invalid
  735.  
  736. IMPLEMENTATION NOTES FOR DOS XMS DRIVERS:
  737. -----------------------------------------
  738.  
  739. -   A DOS XMS driver's control function must begin with code similar to the
  740.     following:
  741.  
  742. XMMControl  proc    far
  743.  
  744.         jmp     short XCControlEntry    ; For "hookability"
  745.         nop                 ; NOTE: The jump must be a short
  746.         nop                 ;  jump to indicate the end of
  747.         nop                 ;  any hook chain.    The nop's
  748.                         ;  allow a far jump to be
  749.                         ;  patched in.
  750. XCControlEntry:
  751.  
  752.  
  753. -   XMS drivers must preserve all registers except those containing
  754.     returned values across any function call.
  755.  
  756. -   XMS drivers are required to hook INT 15h and watch for calls to
  757.     functions 87h (Block Move) and 88h (Extended Memory Available).  The
  758.     INT 15h Block Move function must be hooked so that the state of the A20
  759.     line is preserved across the call.    The INT 15h Extended Memory
  760.     Available function must be hooked to return 0h to protect the HMA.
  761.  
  762. -   In order to maintain compatibility with existing device drivers, DOS XMS
  763.     drivers must not hook INT 15h until the first non-Version Number call
  764.     to the control function is made.
  765.  
  766. -   XMS drivers are required to check for the presence of drivers which
  767.     use the IBM VDISK allocation scheme.  Note that it is not sufficient to
  768.     check for VDISK users at installation time but at the time when the HMA
  769.     is first allocated.  If a VDISK user is detected, the HMA must not be
  770.     allocated.    Microsoft will publish a standard method for detecting
  771.     drivers which use the VDISK allocation scheme.
  772.  
  773. -   XMS drivers which have a fixed number of extended memory handles (most
  774.     do) should implement a command line parameter for adjusting that number
  775.     (suggested name "/NUMHANDLES=")
  776.  
  777. -   XMS drivers should make sure that the major DOS version number is
  778.     greater than or equal to 3 before installing themselves.
  779.  
  780. -   UMBs cannot occupy memory addresses that can be banked by EMS 4.0.
  781.     EMS 4.0 takes precedence over UMBs for physically addressable memory.
  782.  
  783. -   All driver functions must be re-entrant.  Care should be taken to not
  784.     leave interrupts disabled for long periods of time.
  785.  
  786. -   Allocation of a zero length extended memory buffer is allowed.  Programs
  787.     which hook XMS drivers may need to reserve a handle for private use via
  788.     this method.  Programs which hook an XMS driver should pass all requests
  789.     for zero length EMBs to the next driver in the chain.
  790.  
  791. -   Drivers should control the A20 line via an "enable count."    Local En-
  792.     able only enables the A20 line if the count is zero.  It then increments
  793.     the count.    Local Disable only disables A20 if the count is one.  It
  794.     then decrements the count.    Global Enable/Disable keeps a flag which
  795.     indicates the state of A20.  They use Local Enable/Disable to actually
  796.     change the state.
  797.  
  798. IMPLEMENTATION NOTES FOR HIMEM.SYS:
  799. -----------------------------------
  800.  
  801. -   HIMEM.SYS currently supports true AT-compatibles, 386 AT machines, IBM
  802.     PS/2s, AT&T 6300 Plus systems and Hewlett Packard Vectras.
  803.  
  804. -   If HIMEM finds that it cannot properly control the A20 line or if there
  805.     is no extended memory available when HIMEM.SYS is invoked, the driver
  806.     does not install itself.  HIMEM.SYS displays the message "High Memory
  807.     Area Unavailable" when this situation occurs.
  808.  
  809. -   If HIMEM finds that the A20 line is already enabled when it is invoked,
  810.     it will NOT change the A20 line's state.  The assumption is that whoever
  811.     enabled it knew what they were doing.  HIMEM.SYS displays the message "A20
  812.     Line Permanently Enabled" when this situation occurs.
  813.  
  814. -   HIMEM.SYS is incompatible with IBM's VDISK.SYS driver and other drivers
  815.     which use the VDISK scheme for allocating extended memory.  However, 
  816.     HIMEM does attempt to detect these drivers and will not allocate the
  817.     HMA if one is found.
  818.  
  819. -   HIMEM.SYS supports the optional "/HMAMIN=" parameter.  The valid values
  820.     are decimal numbers between 0 and 63.
  821.  
  822. -   By default, HIMEM.SYS has 32 extended memory handles available for use.
  823.     This number may be adjusted with the "/NUMHANDLES=" parameter.  The
  824.     maximum value for this parameter is 128 and the minimum is 0.  Each
  825.     handle currently requires 6 bytes of resident space.
  826.  
  827.  
  828. Copyright (c) 1988, Microsoft Corporation
  829.